/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * <p>Project: jse2303 - Server</p>
 * <p>Powered by webrx On 2023-07-26 10:39:17</p>
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Server {
    public static void main(String[] args) {

        List<Socket> ss = new ArrayList<>();

        try (ServerSocket s = new ServerSocket(1123)) {
            //while (true) {
            Socket c = s.accept();//中断 等待
            System.out.println("有人连线");
            while (true) {
                //接消息
                BufferedReader reader = new BufferedReader(new InputStreamReader(c.getInputStream()));
                System.out.println(reader.readLine());

                //发消息
                PrintWriter writer = new PrintWriter(c.getOutputStream());
                Scanner sc = new Scanner(System.in);
                System.out.print("请输入消息：");
                writer.write(sc.nextLine() + "\r\n");
                writer.flush();
            }
            //}

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
